/*
 *	The countio program prints a vertical histogram of 0 to 9, 
 *	white space and other characters.
 *	Copyright (C) 1989-2089 Sergey Sergeevich Tsybanov All Rights Reserved
 *
 *	Countio is free software: you can redistribute it and/or modify 
 *	it under the terms of the GNU General Public License as published 
 *	by the Free Software Foundation, either version 3 of the License, 
 *	or (at your option) any later version.
 *
 *	Countio is distributed in the hope that it will be useful, but 
 *	WITHOUT ANY WARRANTY; without even the implied warranty of 
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 *	See the GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License 
 *	along with the countio program. 
 *	If not, see <https://www.gnu.org/licenses/>.
 */

#include <stdio.h>

#define CHAR_NEWLINE '\n'
#define CHAR_NINE '9'
#define CHAR_TAB '\t'
#define CHAR_WHITE ' '
#define CHAR_ZERO '0'
#define DIGITS_COUNT 10
#define DIGITS_COUNT_TIMES_THREE 30
#define HISTOGRAM_LENGTH 40
#define HISTOGRAM_LENGTH_MINUS_ONE 39
#define ONE 1
#define THREE 3
#define THIRTY_THREE 33
#define THIRTY_SIX 36
#define ZERO 0

/*
 *	Print a vertical histogram of 0 to 9, white space 
 *	and other characters.
 */
int main( void) {
    char symbol;
    long i, countWhite, countOther;
    long countDigits[ DIGITS_COUNT];

    /*
     *	Zero out the counters.
     */
    countWhite = countOther = ZERO;
    for ( i = ZERO; i < DIGITS_COUNT; ++i)
        countDigits[ i] = ZERO;
    
    /*
     *	Get the count values of inputs.
     */
    while ( ( symbol = getchar()) != EOF)
        if ( symbol >= CHAR_ZERO && symbol <= CHAR_NINE)
            ++countDigits[ symbol - CHAR_ZERO];
        else if ( symbol == CHAR_WHITE || symbol == CHAR_NEWLINE 
                || symbol == CHAR_TAB)
            ++countWhite;
        else
            ++countOther;

    /*
     *	Get the largest count value.
     */
    long largestCount = ZERO;
    for ( i = ZERO; i < DIGITS_COUNT; ++i)
        if ( largestCount < countDigits[ i])
            largestCount = countDigits[ i];
    if ( largestCount < countWhite)
        largestCount = countWhite;
    if ( largestCount < countOther)
        largestCount = countOther;

    /*
     *	Print the histogram.
     */
    printf( "\n========================================\n");
    printf( "=       The IO counting histogram      =\n");
    printf( "========================================\n");
    printf( "=  0  1  2  3  4  5  6  7  8  9  W  O  =\n");
    printf( "========================================\n");
    for ( i = ZERO; i < largestCount; ++i) {
        long j;
        for ( j = ZERO; j < HISTOGRAM_LENGTH; ++j)
            if ( ( j % THREE) == ZERO) {
                if ( j == ZERO || ( j == HISTOGRAM_LENGTH_MINUS_ONE))
                    printf( "=");
                else if ( ( j <= DIGITS_COUNT_TIMES_THREE) 
                        && ( i < countDigits[ j / THREE - ONE]))
                    printf( "X");
                else if (( j == THIRTY_THREE) 
                        && ( i < countWhite))
                    printf( "X");
                else if (( j == THIRTY_SIX) && ( i < countOther)) 
                    printf( "X");
                else
                    printf( " ");
            }
            else
                printf( " ");
        printf( "\n");
    }
    printf( "========================================\n");

    return ZERO;
}